From: Boyuan Yang Date: Fri, 30 Aug 2019 15:18:48 +0000 (-0400) Subject: New upstream version 1.0.5+git20190530 X-Git-Tag: archive/raspbian/1.1.9+ds1-4+rpi1^2^2~15^2~15 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=c2594ca7f36b40ebd5fb64744a329c2eb4a06f38;p=opencc.git New upstream version 1.0.5+git20190530 --- diff --git a/.travis.yml b/.travis.yml index 676a238..7f71b24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,42 @@ -language: cpp -compiler: - - gcc -sudo: required -before_install: - - sudo add-apt-repository -y ppa:chris-lea/node.js - - sudo apt-get update - - sudo apt-get install nodejs -y - - sudo apt-get install doxygen -y - - sudo npm install -g mocha - - sudo npm install -g node-gyp - - sudo npm install -script: make test VERBOSE=1 && make package VERBOSE=1 && make node-test +language: node_js + +cache: + npm: true + ccache: true + +node_js: + - stable + - 10 + - 8 + - 6 + +os: + - linux + - osx + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - doxygen + - g++-4.8 + +# Install scripts. (runs after repo cloning) +install: + - if [ $TRAVIS_OS_NAME == "linux" ]; then export CXX=g++-4.8; fi + # install modules + - npm install --build-from-source + +# Post-install test scripts. +script: + - export PATH="/usr/lib/ccache/:$PATH" + - if [ $TRAVIS_OS_NAME == "linux" ] && [ $TRAVIS_NODE_VERSION == "stable" ]; then + make test VERBOSE=1; + make package VERBOSE=1; + fi + + - npm test + +after_success: + - npm run deploy diff --git a/README.md b/README.md index 9930340..8551558 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Open Chinese Convert 開放中文轉換 [ ![Download](https://api.bintray.com/packages/byvoid/opencc/OpenCC/images/download.svg) ](https://bintray.com/byvoid/opencc/OpenCC/_latestVersion) -[![Build Status](https://travis-ci.org/BYVoid/OpenCC.svg?branch=master)](https://travis-ci.org/BYVoid/OpenCC) +[![Travis](https://img.shields.io/travis/BYVoid/OpenCC.svg)](https://travis-ci.org/BYVoid/OpenCC) +[![AppVeyor](https://img.shields.io/appveyor/ci/Carbo/OpenCC.svg)](https://ci.appveyor.com/project/Carbo/OpenCC) ## Introduction 介紹 @@ -99,19 +100,20 @@ cmake --build build --config Release --target install See https://github.com/gelosie/OpenCC/tree/master/iOS +Or [SwiftyOpenCC](https://github.com/XQS6LB3A/SwiftyOpenCC) + ### Android See [android-opencc](https://github.com/qichuan/android-opencc) ## Projects using Opencc 使用OpenCC的項目 -* [ibus-pinyin](http://code.google.com/p/ibus/) -* [fcitx](http://code.google.com/p/fcitx/) -* [rimeime](http://code.google.com/p/rimeime/) +* [ibus-pinyin](https://github.com/ibus/ibus-pinyin) +* [fcitx](https://github.com/fcitx/fcitx) +* [rimeime](https://rime.im/) * [libgooglepinyin](http://code.google.com/p/libgooglepinyin/) * [ibus-libpinyin](https://github.com/libpinyin/ibus-libpinyin) * [BYVBlog](https://github.com/byvoid/byvblog) -* [豆瓣同城微信](http://weixinqiao.com/douban-event/) * [alfred-chinese-converter](https://github.com/amowu/alfred-chinese-converter) * [GoldenDict](https://github.com/goldendict/goldendict) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..599ad6e --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,40 @@ +version: "{build}" +skip_branch_with_pr: true +skip_tags: true +build: off + +environment: + matrix: + - nodejs_version: stable + - nodejs_version: 10 + - nodejs_version: 8 + - nodejs_version: 6 + +platform: + - x64 + - x86 + +# Install scripts. (runs after repo cloning) +install: + # install Node.js + - ps: Install-Product node $env:nodejs_version $env:platform + # Get the latest stable version of npm + - npm -g i npm@latest + # install modules + - appveyor-retry call npm install --build-from-source + +# to run your custom scripts instead of automatic tests +test_script: + - IF %nodejs_version%==stable cmake -H. -Bbuild -G"Visual Studio 12" + - IF %nodejs_version%==stable cmake --build build --config Release --target install + - npm test + +# pushing entire folder as a zip archive +artifacts: + - path: build/src/tools/Release + name: OpenCC + type: zip + +# to run your custom scripts instead of provider deployments +deploy_script: + - npm run deploy diff --git a/binding.gyp b/binding.gyp index 89ae598..ccc7a0f 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,6 +3,6 @@ "node/global.gypi", "node/configs.gypi", "node/dicts.gypi", - "node/node_binding.gypi", + "node/node_opencc.gypi", ] } diff --git a/data/dictionary/STPhrases.txt b/data/dictionary/STPhrases.txt index 28f14fd..141d137 100644 --- a/data/dictionary/STPhrases.txt +++ b/data/dictionary/STPhrases.txt @@ -9006,7 +9006,7 @@ 化学工厂 化學工廠 化学弹药 化學彈藥 化学当量 化學當量 -化学战斗部 化學戰斗部 +化学战斗部 化學戰鬥部 化学系 化學系 化学纤维 化學纖維 化工厂 化工廠 @@ -29386,7 +29386,7 @@ 杨胜旭 楊勝旭 杨致远 楊致遠 杨苏棣 楊甦棣 -杨采妮 楊採妮 +杨采妮 楊采妮 杨雅筑 楊雅筑 杪秋 杪秋 杭丁顿舞蹈症 杭丁頓舞蹈症 @@ -30259,7 +30259,7 @@ 核当量 核當量 核心 核心 核战 核戰 -核战斗部 核戰斗部 +核战斗部 核戰鬥部 核批 覈批 核技术 核技術 核报 覈報 @@ -46406,7 +46406,7 @@ 间深里 間深裏 闵凶 閔凶 闵子里 閔子裏 -闵采尔 閔採爾 +闵采尔 閔采爾 闷出 悶出 闷在心里 悶在心裏 闷板 悶板 diff --git a/node/binding.cc b/node/binding.cc deleted file mode 100644 index b948e55..0000000 --- a/node/binding.cc +++ /dev/null @@ -1,182 +0,0 @@ -#include -#include - -#include "Config.hpp" -#include "Converter.hpp" -#include "DictConverter.hpp" - -// For faster build -#include "BinaryDict.cpp" -#include "Config.cpp" -#include "Conversion.cpp" -#include "ConversionChain.cpp" -#include "Converter.cpp" -#include "DartsDict.cpp" -#include "Dict.cpp" -#include "DictConverter.cpp" -#include "DictEntry.cpp" -#include "DictGroup.cpp" -#include "MaxMatchSegmentation.cpp" -#include "Segmentation.cpp" -#include "TextDict.cpp" -#include "UTF8Util.cpp" - -using namespace opencc; - -string ToUtf8String(const v8::Local& val) { - Nan::Utf8String utf8(val); - return string(*utf8); -} - -class OpenccBinding : public Nan::ObjectWrap { - struct ConvertRequest { - OpenccBinding* instance; - string input; - string output; - Nan::Callback *callback; - Optional ex; - - ConvertRequest() - : instance(nullptr), ex(Optional::Null()) { - } - }; - - Config config_; - const ConverterPtr converter_; - public: - explicit OpenccBinding(const string configFileName) - : config_(), - converter_(config_.NewFromFile(configFileName)) {} - - virtual ~OpenccBinding() { - } - - string Convert(const string& input) { - return converter_->Convert(input); - } - - static NAN_METHOD(Version) { - info.GetReturnValue().Set(Nan::New(VERSION).ToLocalChecked()); - } - - static NAN_METHOD(New) { - OpenccBinding* instance; - - try { - if (info.Length() >= 1 && info[0]->IsString()) { - const string configFile = ToUtf8String(info[0]); - instance = new OpenccBinding(configFile); - } else { - instance = new OpenccBinding("s2t.json"); - } - } catch (opencc::Exception& e) { - Nan::ThrowError(e.what()); - return; - } - - instance->Wrap(info.This()); - info.GetReturnValue().Set(info.This()); - } - - static NAN_METHOD(Convert) { - if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) { - Nan::ThrowTypeError("Wrong arguments"); - return; - } - - ConvertRequest* conv_data = new ConvertRequest; - conv_data->instance = Nan::ObjectWrap::Unwrap(info.This()); - conv_data->input = ToUtf8String(info[0]); - conv_data->callback = new Nan::Callback(info[1].As()); - conv_data->ex = Optional::Null(); - uv_work_t* req = new uv_work_t; - req->data = conv_data; - uv_queue_work(uv_default_loop(), req, DoConvert, (uv_after_work_cb)AfterConvert); - - return; - } - - static void DoConvert(uv_work_t* req) { - ConvertRequest* conv_data = static_cast(req->data); - OpenccBinding* instance = conv_data->instance; - try { - conv_data->output = instance->Convert(conv_data->input); - } catch (opencc::Exception& e) { - conv_data->ex = Optional(e); - } - } - - static void AfterConvert(uv_work_t* req) { - Nan::HandleScope scope; - ConvertRequest* conv_data = static_cast(req->data); - v8::Local err = Nan::Undefined(); - v8::Local converted = Nan::New(conv_data->output.c_str()).ToLocalChecked(); - if (!conv_data->ex.IsNull()) { - err = Nan::New(conv_data->ex.Get().what()).ToLocalChecked(); - } - const unsigned argc = 2; - v8::Local argv[argc] = { - err, - converted - }; - conv_data->callback->Call(argc, argv); - delete conv_data; - delete req; - } - - static NAN_METHOD(ConvertSync) { - if (info.Length() < 1 || !info[0]->IsString()) { - Nan::ThrowTypeError("Wrong arguments"); - return; - } - - OpenccBinding* instance = Nan::ObjectWrap::Unwrap(info.This()); - - const string input = ToUtf8String(info[0]); - string output; - try { - output = instance->Convert(input); - } catch (opencc::Exception& e) { - Nan::ThrowError(e.what()); - return; - } - - v8::Local converted = Nan::New(output.c_str()).ToLocalChecked(); - info.GetReturnValue().Set(converted); - } - - static NAN_METHOD(GenerateDict) { - if (info.Length() < 4 || !info[0]->IsString() || !info[1]->IsString() - || !info[2]->IsString() || !info[3]->IsString()) { - Nan::ThrowTypeError("Wrong arguments"); - return; - } - const string inputFileName = ToUtf8String(info[0]); - const string outputFileName = ToUtf8String(info[1]); - const string formatFrom = ToUtf8String(info[2]); - const string formatTo = ToUtf8String(info[3]); - try { - opencc::ConvertDictionary(inputFileName, outputFileName, formatFrom, formatTo); - } catch (opencc::Exception& e) { - Nan::ThrowError(e.what()); - } - } - - static NAN_MODULE_INIT(Init) { - // Prepare constructor template - v8::Local tpl = Nan::New(OpenccBinding::New); - tpl->SetClassName(Nan::New("Opencc").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - // Methods - Nan::SetMethod(tpl, "version", Version); - Nan::SetMethod(tpl, "generateDict", GenerateDict); - // Prototype - Nan::SetPrototypeMethod(tpl, "convert", Convert); - Nan::SetPrototypeMethod(tpl, "convertSync", ConvertSync); - // Constructor - v8::Local cons = Nan::GetFunction(tpl).ToLocalChecked(); - Nan::Set(target, Nan::New("Opencc").ToLocalChecked(), cons); - } -}; - -NODE_MODULE(binding, OpenccBinding::Init); diff --git a/node/dicts.gypi b/node/dicts.gypi index 3b96381..0ea3452 100644 --- a/node/dicts.gypi +++ b/node/dicts.gypi @@ -152,7 +152,7 @@ "action": ["node", "<(cmd)", "<(input)", "<@(_outputs)"] }], "dependencies": [ - "binding" + "opencc" ] }] } diff --git a/node/node_binding.gypi b/node/node_binding.gypi deleted file mode 100644 index 6022195..0000000 --- a/node/node_binding.gypi +++ /dev/null @@ -1,14 +0,0 @@ -{ - "targets": [{ - "target_name": "binding", - "sources": [ - "../node/binding.cc", - ], - "include_dirs": [ - "../src", - "../deps/darts-clone", - "../deps/rapidjson-0.11", - " +#include + +#include "Config.hpp" +#include "Converter.hpp" +#include "DictConverter.hpp" + +// For faster build +#include "BinaryDict.cpp" +#include "Config.cpp" +#include "Conversion.cpp" +#include "ConversionChain.cpp" +#include "Converter.cpp" +#include "DartsDict.cpp" +#include "Dict.cpp" +#include "DictConverter.cpp" +#include "DictEntry.cpp" +#include "DictGroup.cpp" +#include "MaxMatchSegmentation.cpp" +#include "Segmentation.cpp" +#include "TextDict.cpp" +#include "UTF8Util.cpp" + +using namespace opencc; + +string ToUtf8String(const v8::Local& val) { + Nan::Utf8String utf8(val); + return string(*utf8); +} + +class OpenccBinding : public Nan::ObjectWrap { + struct ConvertRequest { + OpenccBinding* instance; + string input; + string output; + Nan::Callback *callback; + Optional ex; + + ConvertRequest() + : instance(nullptr), ex(Optional::Null()) { + } + }; + + Config config_; + const ConverterPtr converter_; + public: + explicit OpenccBinding(const string configFileName) + : config_(), + converter_(config_.NewFromFile(configFileName)) {} + + virtual ~OpenccBinding() { + } + + string Convert(const string& input) { + return converter_->Convert(input); + } + + static NAN_METHOD(Version) { + info.GetReturnValue().Set(Nan::New(VERSION).ToLocalChecked()); + } + + static NAN_METHOD(New) { + OpenccBinding* instance; + + try { + if (info.Length() >= 1 && info[0]->IsString()) { + const string configFile = ToUtf8String(info[0]); + instance = new OpenccBinding(configFile); + } else { + instance = new OpenccBinding("s2t.json"); + } + } catch (opencc::Exception& e) { + Nan::ThrowError(e.what()); + return; + } + + instance->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + } + + static NAN_METHOD(Convert) { + if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) { + Nan::ThrowTypeError("Wrong arguments"); + return; + } + + ConvertRequest* conv_data = new ConvertRequest; + conv_data->instance = Nan::ObjectWrap::Unwrap(info.This()); + conv_data->input = ToUtf8String(info[0]); + conv_data->callback = new Nan::Callback(info[1].As()); + conv_data->ex = Optional::Null(); + uv_work_t* req = new uv_work_t; + req->data = conv_data; + uv_queue_work(uv_default_loop(), req, DoConvert, (uv_after_work_cb)AfterConvert); + + return; + } + + static void DoConvert(uv_work_t* req) { + ConvertRequest* conv_data = static_cast(req->data); + OpenccBinding* instance = conv_data->instance; + try { + conv_data->output = instance->Convert(conv_data->input); + } catch (opencc::Exception& e) { + conv_data->ex = Optional(e); + } + } + + static void AfterConvert(uv_work_t* req) { + Nan::HandleScope scope; + ConvertRequest* conv_data = static_cast(req->data); + v8::Local err = Nan::Undefined(); + v8::Local converted = Nan::New(conv_data->output.c_str()).ToLocalChecked(); + if (!conv_data->ex.IsNull()) { + err = Nan::New(conv_data->ex.Get().what()).ToLocalChecked(); + } + const unsigned argc = 2; + v8::Local argv[argc] = { + err, + converted + }; + conv_data->callback->Call(argc, argv); + delete conv_data; + delete req; + } + + static NAN_METHOD(ConvertSync) { + if (info.Length() < 1 || !info[0]->IsString()) { + Nan::ThrowTypeError("Wrong arguments"); + return; + } + + OpenccBinding* instance = Nan::ObjectWrap::Unwrap(info.This()); + + const string input = ToUtf8String(info[0]); + string output; + try { + output = instance->Convert(input); + } catch (opencc::Exception& e) { + Nan::ThrowError(e.what()); + return; + } + + v8::Local converted = Nan::New(output.c_str()).ToLocalChecked(); + info.GetReturnValue().Set(converted); + } + + static NAN_METHOD(GenerateDict) { + if (info.Length() < 4 || !info[0]->IsString() || !info[1]->IsString() + || !info[2]->IsString() || !info[3]->IsString()) { + Nan::ThrowTypeError("Wrong arguments"); + return; + } + const string inputFileName = ToUtf8String(info[0]); + const string outputFileName = ToUtf8String(info[1]); + const string formatFrom = ToUtf8String(info[2]); + const string formatTo = ToUtf8String(info[3]); + try { + opencc::ConvertDictionary(inputFileName, outputFileName, formatFrom, formatTo); + } catch (opencc::Exception& e) { + Nan::ThrowError(e.what()); + } + } + + static NAN_MODULE_INIT(Init) { + // Prepare constructor template + v8::Local tpl = Nan::New(OpenccBinding::New); + tpl->SetClassName(Nan::New("Opencc").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + // Methods + Nan::SetMethod(tpl, "version", Version); + Nan::SetMethod(tpl, "generateDict", GenerateDict); + // Prototype + Nan::SetPrototypeMethod(tpl, "convert", Convert); + Nan::SetPrototypeMethod(tpl, "convertSync", ConvertSync); + // Constructor + v8::Local cons = Nan::GetFunction(tpl).ToLocalChecked(); + Nan::Set(target, Nan::New("Opencc").ToLocalChecked(), cons); + } +}; + +NODE_MODULE(binding, OpenccBinding::Init); diff --git a/node/opencc.js b/node/opencc.js index 70f9564..67be63f 100644 --- a/node/opencc.js +++ b/node/opencc.js @@ -27,9 +27,10 @@ */ var path = require('path'); -var binding = require('../build/Release/binding'); +var bindingPath = require('node-pre-gyp').find(require.resolve('../package.json')); +var binding = require(bindingPath); -var assetsPath = path.resolve(__dirname, '../build/Release'); +var assetsPath = path.dirname(bindingPath); var getConfigPath = function (config) { var configPath = config; if (config[0] !== '/' && config[1] !== ':') { diff --git a/package.json b/package.json index 4d7233b..77e9aea 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,15 @@ "license": "Apache-2.0", "main": "node/opencc.js", "scripts": { - "test": "mocha -R spec node/test.js" + "test": "mocha -R spec node/test.js", + "deploy": "node-pre-gyp package && (node-pre-gyp-github publish --release || exit 0)", + "install": "node-pre-gyp install --fallback-to-build || node-pre-gyp rebuild" + }, + "binary": { + "module_name": "opencc", + "module_path": "./build/Release/", + "host": "https://github.com/BYVoid/OpenCC/releases/download/", + "remote_path": "{version}" }, "repository": { "type": "git", @@ -24,9 +32,11 @@ "Traditional Chinese" ], "devDependencies": { - "mocha": "2.2.5" + "mocha": "^3.5.0", + "node-pre-gyp-github": "^1.3.1" }, "dependencies": { - "nan": "^2.5.1" + "nan": "^2.7.0", + "node-pre-gyp": "^0.6.36" } } diff --git a/src/BinaryDict.cpp b/src/BinaryDict.cpp index 87a215d..bfeb3ac 100644 --- a/src/BinaryDict.cpp +++ b/src/BinaryDict.cpp @@ -24,7 +24,7 @@ using namespace opencc; size_t BinaryDict::KeyMaxLength() const { size_t maxLength = 0; for (const DictEntry* entry : *lexicon) { - maxLength = std::max(maxLength, entry->KeyLength()); + maxLength = (std::max)(maxLength, entry->KeyLength()); } return maxLength; } diff --git a/src/DartsDict.cpp b/src/DartsDict.cpp index 75f4c3d..07ebec8 100644 --- a/src/DartsDict.cpp +++ b/src/DartsDict.cpp @@ -135,7 +135,7 @@ DartsDictPtr DartsDict::NewFromDict(const Dict& thatDict) { for (size_t i = 0; i < lexiconCount; i++) { const DictEntry* entry = lexicon->At(i); keys[i] = entry->Key(); - maxLength = std::max(entry->KeyLength(), maxLength); + maxLength = (std::max)(entry->KeyLength(), maxLength); } doubleArray->build(lexicon->Length(), &keys[0]); dict->lexicon = lexicon; diff --git a/src/DictConverter.hpp b/src/DictConverter.hpp index f59c5ec..7d392a1 100644 --- a/src/DictConverter.hpp +++ b/src/DictConverter.hpp @@ -25,6 +25,6 @@ namespace opencc { * Converts a dictionary from a format to another. * @ingroup opencc_cpp_api */ -void ConvertDictionary(const string inputFileName, const string outputFileName, +OPENCC_EXPORT void ConvertDictionary(const string inputFileName, const string outputFileName, const string formatFrom, const string formatTo); } diff --git a/src/Exception.hpp b/src/Exception.hpp index 33cb5d9..98ebb60 100644 --- a/src/Exception.hpp +++ b/src/Exception.hpp @@ -24,9 +24,8 @@ #include "Export.hpp" -#ifdef _MSC_VER - -// Until Visual Studio 2013 (12.0), C++ 11 "noexcept" qualifier is not supported +#if defined(_MSC_VER) && _MSC_VER < 1900 +// Before Visual Studio 2015 (14.0), C++ 11 "noexcept" qualifier is not supported #define noexcept #endif // ifdef _MSC_VER diff --git a/src/PhraseExtractTest.cpp b/src/PhraseExtractTest.cpp index 3eced58..e1c8fef 100644 --- a/src/PhraseExtractTest.cpp +++ b/src/PhraseExtractTest.cpp @@ -16,6 +16,8 @@ * limitations under the License. */ +#include + #include "PhraseExtract.hpp" #include "TestUtils.hpp" diff --git a/src/TextDict.cpp b/src/TextDict.cpp index a6d29f3..73f5119 100644 --- a/src/TextDict.cpp +++ b/src/TextDict.cpp @@ -25,7 +25,7 @@ static size_t GetKeyMaxLength(const LexiconPtr& lexicon) { size_t maxLength = 0; for (const auto& entry : *lexicon) { size_t keyLength = entry->KeyLength(); - maxLength = std::max(keyLength, maxLength); + maxLength = (std::max)(keyLength, maxLength); } return maxLength; }